import {
  createWebHashHistory,
  createRouter
} from 'vue-router'
import home from './modules/home.js'
export const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      name: 'home',
      component: () => import("@/views/home.vue"),
      redirect: "/home/homePage",
      meta: {
        //懒加载
        keepAlive: true
      },
      children: [
        ...home
      ]
    },
    {
      path: '/about',
      name: 'about',
      component: () => import("@/views/about.vue"),
      meta: {
        keepAlive: true
      }
    }
  ],

  //控制滚动条是否滚动到顶部
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return {
        x: 0,
        y: 0
      }
    }
  }

})